define(function(require, exports, module) {
    'use strict';
    
    var rk = require('rk');
    require('../../../core/apps/feed/feed');
    require('./todaywork/todayWorkCtrl');
    require('./prm/prmHeadlineCtrl');
    require('./dashboard/dashboardCtrl');

    module.exports = {
        init: function() {
            var $panel = rk.showPageView('rk-panel', rk.i18n('INDEX_PAGE')), //$('#pagecontent div.rk-panel').show(),
                $feedPanel = $panel.find('div.feed-panel'),
                $portalPanel = $panel.find('div.portal-panel'),
                $chartPanel = $('#index_chart_panel'),
                $taskPanel = $('#index_task_panel'),
                $prmPanel = $("#index_prm_panel");
            var height;
            setInterval(function() {
                var h = $portalPanel.height();
                if (h != height) {
                    $feedPanel.css('min-height', height = h);
                }
            }, 1000);

            var arCallbacks = [];

            $panel.beScroll({
                whileScrolling: function() {
                    var scrollTop = Math.abs(parseInt($panel.find('.mCSB_container').css('top'), 10));
                    if (scrollTop > $panel.closest('.mCustomScrollbar').height()) {
                        $feedPanel.find('a.js-gototop').show();
                    } else {
                        $feedPanel.find('a.js-gototop').hide();
                    }
                },
                onTotalScroll: function() {
                    for (var i = 0, len = arCallbacks.length; i < len; i++) {
                        var fn = arCallbacks[i];
                        if ($.isFunction(fn)) {
                            fn();
                        }
                    }
                },
                onTotalScrollOffset: 120,
                alwaysTriggerOffsets: true
            });

            $feedPanel.feed2015({
                scrollRegister: function(fn) {
                    arCallbacks.push(fn);
                }
            });

            //加载今天工作
            $taskPanel.todayWorkCtrl();
            //加载prm头条
            if(SESSION.hasPrmContentAccess == '1') {
                $prmPanel.prmHeadlineCtrl();
            }
            //加载仪表盘
            if(!WANXUE) {
                if (window.SESSION.hasCrmAccess) {
                    $chartPanel.dashboardCtrl();
                }
            }
        }
    };
});
